# -*- coding: UTF-8 -*-
from flask import has_app_context
from flask_jwt_extended import create_access_token as lj_auth_gen_token, get_jwt_identity as lj_auth_username, get_jwt


def lj_auth_user():
    if not has_app_context():
        return
    from lj_action.action_data import init_action_data
    account_orm = init_action_data('account')
    current_user = lj_auth_username()
    return account_orm.listFilter(account_orm.entity.account == current_user)[0]


def lj_auth_id():
    user = lj_auth_user()
    if not user:
        return
    return user.get('id')


def get_data(key):
    return get_jwt()[key]
